<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .test{
            font-size: 30px;
        }
    </style>
</head>
<body>
    <h1>本地存储</h1>
   <input type="text" class="test">
   <button onclick="myset()">存</button>
   <button onclick="myget()">取</button>
   <button onclick="myclear()">清空</button>
</body>
<script>
    function myset(){
        var test=document.querySelector('.test').value;
        localStorage.setItem('stname',test);
        console.log(test);
    }
    function myget(){
        var v=localStorage.getItem('stname');
        document.querySelector('.test').value=v;
    }
    function myclear(){
        localStorage.clear();
        console.log('已清空');
    }
</script>
</html>
